import { Controller, Get,Post, Param, ParseIntPipe, Body, Delete,Request, Put } from '@nestjs/common';
import { MenuService } from './menu.service';
import { success } from 'src/utils';
@Controller('menu')
export class MenuController {
    constructor(private readonly userService: MenuService) {}
    @Post('menuList')
    async menuList(@Body('ids') ids:number[],@Request() req:any){
        const permissions = req.user.permissions
        if(ids&&ids.length > 0){
            const resInfo =  await this.userService.findListByIds(ids)
            return success(resInfo, '获取成功');
        }else{
            const res =  await this.userService.findList(permissions)
            return success(res, '获取成功');
        }
        
    }
    @Post('addMenu')
    async addMenu(@Body() data:any,@Request() req:any){
        const res =  await this.userService.addMenu({...data,user_id: req.user.id})
        return success(res, data.id? '修改成功': '创建成功');
    }
    @Post('editMenu')
    async editMenu(@Body() data:any,@Request() req:any){
        const res =  await this.userService.editMenu({...data,user_id: req.user.id})
        return success(res, data.id? '修改成功': '创建成功');
    }
    @Get('menuDetail/:id')
    async addressDetail(@Param('id',ParseIntPipe) id: number){
        const res =  await this.userService.oneMenu(id)
        return success(res, '获取成功');
    }
    @Delete('menuDelete/:id')
    async menuDelete(@Param('id',ParseIntPipe) id: number){
        const res =  await this.userService.oneMenu(id)
        return success(res, '删除');
    }
}
